<?php

define('TWITTER_ACC_PARENT', 'object');
define('TWITTER_ACC_SUBTYPE', 'twitter_acc');
define('TWITTER_ACC_CLASS', 'TwitterAccount');

//define('GAMECENTER_ACC_HOMETOWN', 'hometown');
//define('GAMECENTER_ACC_LASTNAME', 'lastname');
define('TWITTER_ACC_ALIAS', 'alias');
define('TWITTER_ACC_ID', 'id');

register_entity_type(TWITTER_ACC_PARENT, TWITTER_ACC_SUBTYPE);
// This operation only affects the db on the first call for this subtype
// If you change the class name, you'll have to hand-edit the db
add_subtype(TWITTER_ACC_PARENT, TWITTER_ACC_SUBTYPE, TWITTER_ACC_CLASS);

class TwitterAccount extends ElggObject {

    protected function initialise_attributes() {
        parent::initialise_attributes ();
        $this->attributes ['subtype'] = TWITTER_ACC_SUBTYPE;
        $this->access_id = ACCESS_PUBLIC;
    }

    public function __construct($guid = null) {
        parent::__construct($guid);
    }

    public function setOwner($guid) {
        $this->owner_guid = $guid;
        $this->save();
    }

    // more customizations here
    public function saveAccount($id, $alias) {
        $this->save();
        $this->setMetaData('greengar_account', 1);
        $this->setMetaData(TWITTER_ACC_ID, $id, 'text');
        $this->setMetaData(TWITTER_ACC_ALIAS, $alias, 'text');
        //$this->setMetaData(GAMECENTER_ACC_LASTNAME, $lastname, 'text');
        //$this->setMetaData(GAMECENTER_ACC_HOMETOWN, $hometown, 'text');
        return $this->save();
    }

    public function toArray() {
        return array(
            'guid' => $this->getGUID(),
            'id' => $this->id,
            //'firstname' => $this->firstname,
            //'lastname' => $this->lastname,
            'alias' => $this->alias,
            'type' => 'Twitter'
        );
    }

}

?>